package com.zhangyu.shadow.repair.delegate.maintain;

import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.zhangyu.shadow.repair.config.RepairItemType;
import com.zhangyu.shadow.repair.delegate.bean.DeptBean;
import com.zhangyu.shadow.repair.delegate.bean.RepairTypeBean;
import com.zhangyu.shadow.repair.delegate.repair.ExpandableItemAdapter;
import com.zhangyu.shadow.repair.delegate.repair.entity.Level0Item;
import com.zhangyu.shadow.repair.delegate.repair.entity.Level1Item;

import java.util.ArrayList;
import java.util.List;

import st.lib.base.ui.recycler.MultipleField;
import st.lib.base.ui.recycler.MultipleItemEntity;

/**
 * @author zhangyu
 * @date 2018/3/28
 */

class PostReportData {

    /**
     * Id : 1
     * VehicleCode : 82223
     * InFactoryTime : 可以不填
     * ListConfirm : [{"Classification":{"Code":"01"},"ListTrouble":[{"TroubleType":{"Id":1,"Code":"01","Name":"发动机发吐"}}]},{"Classification":{"Code":"02"},"ListTrouble":[{"TroubleType":{"Id":2,"Code":"02","Name":"刹车失灵"}}]}]
     */

    private int id;
    private ListConfirmBean.ClassificationBean vehicle;
    private DeptBean shiftGroup;
    private DeptBean dept;
    private String reportTime;
    private String inFactoryTime;
    private List<ListConfirmBean> listTrouble;
    private RepairTypeBean repairTypeReal;
    private DriverBean driver;

    public RepairTypeBean getRepairTypeReal() {
        return repairTypeReal;
    }

    public void setRepairTypeReal(RepairTypeBean repairTypeReal) {
        this.repairTypeReal = repairTypeReal;
    }

    public String getReportTime() {
        return reportTime;
    }

    public void setReportTime(String reportTime) {
        this.reportTime = reportTime;
    }

    public String getInFactoryTime() {
        return inFactoryTime;
    }

    public void setInFactoryTime(String inFactoryTime) {
        this.inFactoryTime = inFactoryTime;
    }

    public DeptBean getShiftGroup() {
        return shiftGroup;
    }

    public void setShiftGroup(DeptBean shiftGroup) {
        this.shiftGroup = shiftGroup;
    }

    public DeptBean getDept() {
        return dept;
    }

    public void setDept(DeptBean dept) {
        this.dept = dept;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public ListConfirmBean.ClassificationBean getVehicle() {
        return vehicle;
    }

    public void setVehicle(ListConfirmBean.ClassificationBean vehicle) {
        this.vehicle = vehicle;
    }

    public DriverBean getDriver() {
        return driver;
    }

    public void setDriver(DriverBean driver) {
        this.driver = driver;
    }

    public List<ListConfirmBean> getListTrouble() {
        return listTrouble;
    }

    public void setListTrouble(List<ListConfirmBean> listTrouble) {
        this.listTrouble = listTrouble;
    }

    public static class DriverBean {
        private String code;

        private int id;

        private String name;

        public String getCode() {
            return code;
        }

        public int getId() {
            return id;
        }

        public DriverBean setId(int id) {
            this.id = id;
            return this;
        }

        public String getName() {
            return name;
        }

        public DriverBean setName(String name) {
            this.name = name;
            return this;
        }

        public DriverBean setCode(String code) {
            this.code = code;
            return this;
        }
    }

    public static class ListConfirmBean {
        /**
         * Classification : {"Code":"01"}
         * ListTrouble : [{"TroubleType":{"Id":1,"Code":"01","Name":"发动机发吐"}}]
         */

        private ClassificationBean classification;
        private TroubleTypeBean troubleType;

        public ClassificationBean getClassification() {
            return classification;
        }

        public void setClassification(ClassificationBean classification) {
            this.classification = classification;
        }

        public TroubleTypeBean getTroubleType() {
            return troubleType;
        }

        public void setTroubleType(TroubleTypeBean troubleType) {
            this.troubleType = troubleType;
        }

        public static class ClassificationBean {
            /**
             * Code : 01
             */

            private String code;

            public String getCode() {
                return code;
            }

            public ClassificationBean setCode(String code) {
                this.code = code;
                return this;
            }
        }

        public static class TroubleTypeBean {
            /**
             * Id : 1
             * Code : 01
             * Name : 发动机发吐
             */

            private int id;
            private String code;
            private String name;

            public int getId() {
                return id;
            }

            public void setId(int id) {
                this.id = id;
            }

            public String getCode() {
                return code;
            }

            public void setCode(String code) {
                this.code = code;
            }

            public String getName() {
                return name;
            }

            public void setName(String name) {
                this.name = name;
            }
        }
    }

    public static PostReportData getPostReportData(int id,
                                                   String vehicleCode,
                                                   int driverId,
                                                   String driverCode,
                                                   String driverName,
                                                   ExpandableItemAdapter itemAdapter) {
        PostReportData postRepairData = new PostReportData();
        postRepairData.setId(id);
        postRepairData.setVehicle(new ListConfirmBean.ClassificationBean().setCode(vehicleCode));
        postRepairData.setDriver(new DriverBean().setCode(driverCode).setId(driverId).setName(driverName));
        List<ListConfirmBean> listConfirmBeans = new ArrayList<>();
        List<MultiItemEntity> entityList = itemAdapter.getData();
        int size = entityList.size();
        for (int i = 1; i < size; i += 2) {
            Level1Item level1Item = (Level1Item) entityList.get(i);
            Level0Item level0Item = (Level0Item) entityList.get(i - 1);
            List<MultipleItemEntity> itemEntities = level1Item.mMultiItemEntities;
            if (itemEntities != null) {
                for (MultipleItemEntity entity : itemEntities) {
                    ListConfirmBean listConfirmBean = new ListConfirmBean();
                    listConfirmBean.setClassification(new ListConfirmBean.ClassificationBean()
                            .setCode(level0Item.mCode));
                    ListConfirmBean.TroubleTypeBean troubleType = new ListConfirmBean.TroubleTypeBean();
                    troubleType.setId((Integer) entity.getField(MultipleField.ID));
                    troubleType.setCode((String) entity.getField(RepairItemType.ITEM_CODE));
                    troubleType.setName((String) entity.getField(MultipleField.NAME));
                    listConfirmBean.setTroubleType(troubleType);

                    listConfirmBeans.add(listConfirmBean);
                }
            }
        }
        postRepairData.setListTrouble(listConfirmBeans);
        return postRepairData;
    }

//    public static String getJsonData(PostReportData postRepairData, WeakHashMap<String, Object> baseInfo) {
//
//    }
}
